<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html>
<head>
    <meta charset="utf-8">
    <title>出车记录</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/static/layui/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/static/layui/css/public.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form">
    <blockquote class="layui-elem-quote quoteBox">
        <form class="layui-form" id="searchForm">
            <div class="layui-inline">
                <div class="layui-inline">
                    <div class="layui-inline">
                        <h5>开始时间：</h5>
                    </div>
                    <div class="layui-input-inline">
                        <input type="text" name="startDate" id="startDate" placeholder="请输入开始时间" class="layui-input usetime">
                    </div>
                    <div class="layui-inline">
                        <h5>结束时间：</h5>
                    </div>
                    <div class="layui-input-inline">
                        <input type="text" name="endDate" id="endDate" placeholder="请输入结束时间" class="layui-input usetime">
                    </div>
                    <a class="layui-btn search_btn" data-type="reload" id="searchVal">搜索</a>
                </div>
            </div>
        </form>
    </blockquote>
    <table id="applyUseList" lay-filter="applyUseList"></table>
    <!--操作-->
    <script type="text/html" id="applyUseListBar">

        <shiro:hasPermission name="out:look">
            <a class="layui-btn layui-btn-xs" lay-event="check">预览</a>
        </shiro:hasPermission>
        <shiro:hasPermission name="out:del">
            <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
        </shiro:hasPermission>


    </script>
</form>
<script type="text/javascript" src="/static/layui/layui/layui.js"></script>
<script>
    layui.use(['form','layer','laydate','table','laytpl'],  function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laytpl = layui.laytpl,
            table = layui.table,
            laydate=layui.laydate;

        //用户列表
        var tableIns = table.render({
            elem: '#applyUseList',
            url : '/outWardRecord/findAllOutWardRecord',
            cellMinWidth : 95,
            page : true,
            height : "full-125",
            limits : [5,10,15,20,25],
            limit : 5,
            id : "userListTable",
            cols : [[
                {field: 'car', title: '车牌号', minWidth:60, align:"center",templet:function (d) {
                        return d.car.carplate;
                    }},
                {field: 'driver', title: '司机', minWidth:60, align:"center",templet:function (d) {
                        return d.driver.dirvername;
                    }},
                {field: 'dept', title: '申请部门', minWidth:60, align:"center",templet:function (d) {
                        return d.dept.deptname;
                    }},
                {field: 'starttime', title: '用车时间', minWidth:80, align:"center"},
                {field: 'endtime', title: '实际归还时间', minWidth:60, align:"center"},
                {field: 'suite', title: '用车人', minWidth:60, align:"center"},
                {field: 'destination', title: '目的地', minWidth:60, align:"center"},
                {title: '操作', minsWidth:80, templet:'#applyUseListBar',align:"center"}
            ]]
        });

        // 搜索
        $("#searchVal").click(function () {
            var startDate=$('#startDate').val();
            var endDate = $('#endDate').val();
            tableIns.reload({
                where:{
                    startDate:startDate,
                    endDate:endDate
                }
            })
        });

        //选择表格中的操作按钮
        table.on("tool(applyUseList)",function (obj) {
            switch (obj.event) {
                case 'del':
                    delApplyUse(obj.data.outwardid);
                    break;
                case 'check':
                    checkUse(obj.data.outwardid);
                    break;
            }
        });

        //删除功能函数
        function delApplyUse(applyid) {
            layer.confirm('确定要删除该条记录吗？', function(index){
                $.ajax({
                    url:"/outWardRecord/delOutward",
                    type:"post",
                    data:{"outwardid":outwardid},
                    success:function (data) {
                        if(data.code==1001){
                            layui.layer.msg(data.msg);
                            tableIns.reload();
                        }else{
                            layui.layer.msg(data.msg);
                        }
                    }
                });
                layer.close(index);
            });
        }

        //进入预览界面
        function checkUse(data) {
            var userLayer=layui.layer.open({
                type:2,
                title:'预览出车信息',
                content:'/outWardRecord/outWardRecordCheck?outwardid='+data,
                shade:0.3,
                anim:0,
                area:["48%","90%"],
                maxmin:true,
                success:function (laero,index) {
                    setTimeout(function(){
                        layui.layer.tips('点击此处返回列表', '.layui-layer-setwin .layui-layer-close', {
                            tips: 3
                        });
                    },500);
                }
            });
        }

        $(".usetime").each(function () {
            laydate.render({
                elem:this,
                theme: 'grid',
                type: 'datetime'
            });
        });



    });
</script>
</body>
</html>